package com.zhenyi.jiahua.interceptor;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.weixin.sdk.kit.IpKit;
import com.utils.PathUtils;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.file.FileWriter;

public class ApiLogInterceptor implements Interceptor {

	@Override
	public void intercept(Invocation inv) {
		inv.invoke();
		try {
			String method = inv.getMethodName();
			String ip = IpKit.getRealIpV2(inv.getController().getRequest());
			String filePath = PathUtils.getFile("jh", "temp", "excel", method + "Api.txt");
			FileWriter fileWriter = new FileWriter(filePath);
			fileWriter.append(DateUtil.now() + " " + ip + "\n");
			// FileReader reader = new FileReader(filePath);
			// String countStr = reader.readString();
			// if (StrKit.isBlank(countStr)) {
			// fileWriter.write("1");
			// } else {
			// Integer number = Integer.parseInt(countStr);
			// fileWriter.write(String.valueOf(number + 1));
			// }
		} catch (Exception e) {
		}
	}

}
